﻿using System.Windows.Forms;

namespace InstallPartner
{
    /// <summary>
    /// Provides the UI for adding or modifying application information.
    /// </summary>
    public partial class AddApplicationDialog : Form
    {
        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="AddApplicationDialog"/> class.
        /// </summary>
        public AddApplicationDialog()
        {
            InitializeComponent();
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets or sets the application group.
        /// </summary>
        /// <value>The application group.</value>
        public string ApplicationGroup
        {
            get
            {
                return cboGroup.Text;
            }

            set
            {
                cboGroup.Text = value;
            }
        }

        /// <summary>
        /// Gets or sets the name of the application.
        /// </summary>
        /// <value>The name of the application.</value>
        public string ApplicationName
        {
            get
            {
                return txtName.Text;
            }

            set
            {
                txtName.Text = value;
            }
        }

        /// <summary>
        /// Gets or sets the command line.
        /// </summary>
        /// <value>The command line.</value>
        public string CommandLine
        {
            get
            {
                return txtCommandLine.Text;
            }

            set
            {
                txtCommandLine.Text = value;
            }
        }

        /// <summary>
        /// Gets or sets the arguments.
        /// </summary>
        /// <value>The arguments.</value>
        public string Arguments
        {
            get
            {
                return txtArguments.Text;
            }

            set
            {
                txtArguments.Text = value;
            }
        }

        #endregion

        #region Event Handlers

        /// <summary>
        /// Values the changed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void ValueChanged(object sender, System.EventArgs e)
        {
            btnOk.Enabled = cboGroup.Text.Length > 0 && txtName.Text.Length > 0 && txtCommandLine.Text.Length > 0;
        }

        /// <summary>
        /// Handles the Click event of the btnBrowseCommand control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btnBrowseCommand_Click(object sender, System.EventArgs e)
        {
            openFileDialog1.CheckFileExists = true;
            openFileDialog1.DefaultExt = "*.exe";
            openFileDialog1.FileName = txtCommandLine.Text;
            openFileDialog1.Filter = "Batch Files (*.bat)|*.bat|Application Files (*.exe)|*.exe|All Files (*.*)|*.*";
            openFileDialog1.FilterIndex = 0;
            openFileDialog1.Multiselect = false;
            openFileDialog1.Title = "Select Application to be Installed";

            if (openFileDialog1.ShowDialog(this) != DialogResult.Cancel)
            {
                txtCommandLine.Text = openFileDialog1.FileName;
            }
        }

        #endregion
    }
}
